package com.example.yin.controller;

import com.example.yin.common.ErrorMessage;
import com.example.yin.common.SuccessMessage;
import com.example.yin.domain.Article;
import com.example.yin.domain.ArticleComment;
import com.example.yin.service.ArticleCommentService;
import com.example.yin.service.ArticleService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author
 * @description
 * @createDate 2023/6/26
 */

@RestController
@RequestMapping("/articlecomment")
public class ArticleCommentController {

    @Autowired
    ArticleCommentService articleCommentService;

    @RequestMapping("/add")
    public Object add(@RequestBody ArticleComment article){
        boolean res = articleCommentService.add(article);
        if (res) {
            return new SuccessMessage<ObjectUtils.Null>("添加成功").getMessage();
        } else {
            return new ErrorMessage("添加失败").getMessage();
        }
    }

    @RequestMapping("/delete")
    public Object delete(Integer id){
        boolean res = articleCommentService.delete(id);
        if (res) {
            return new SuccessMessage<ObjectUtils.Null>("删除成功").getMessage();
        } else {
            return new ErrorMessage("删除失败").getMessage();
        }
    }

    @RequestMapping("/deletebycommentid")
    public Object deleteByCommentId(Integer id){
        boolean res = articleCommentService.deleteByCommentId(id);
        if (res) {
            return new SuccessMessage<ObjectUtils.Null>("删除成功").getMessage();
        } else {
            return new ErrorMessage("删除失败").getMessage();
        }
    }

    @RequestMapping("/update")
    public Object update(@RequestBody ArticleComment article){
        boolean res = articleCommentService.update(article);
        if (res) {
            return new SuccessMessage<ObjectUtils.Null>("更新成功").getMessage();
        } else {
            return new ErrorMessage("更新失败").getMessage();
        }
    }

    @RequestMapping("/list")
    public Object getList(@RequestBody ArticleComment articleComment){
        List<ArticleComment> res = articleCommentService.getList(articleComment);
        if (res != null) {
            return new SuccessMessage("查询成功",res).getMessage();
        } else {
            return new ErrorMessage("查询失败").getMessage();
        }
    }
}
